package jia.temp;

import jia.core.Space;
import jia.game.FirstPersonViewport;

import javax.vecmath.Vector2d;
import java.awt.*;

public class MazeViewport extends FirstPersonViewport {
    private static final String START_MSG = "Find The Exit";
    private static final String END_MSG = "You Win!";
    
    //====================================================
    /**
     *
     */
    protected void renderView(Graphics2D g) {
        super.renderView(g);
        Vector2d myPos = gameState.getPlayerState().getPosition();
        Space mySpace = gameState.getPlayerState().getCurrentModule().getSpace(myPos);
        if (mySpace != null) {
            if (mySpace.getFlags().hasFlag(MazeModule.START_SPACE_FLAG)) {
                g.setColor(Color.RED);
                int fontX = g.getFontMetrics().charsWidth(START_MSG.toCharArray(), 0, START_MSG.length());
                fontX /= 2;
                g.drawString(START_MSG, (getWidth() / 2) - fontX, getHeight() / 2);
            } else if (mySpace.getFlags().hasFlag(MazeModule.END_SPACE_FLAG)) {
                g.setColor(Color.GREEN);
                int fontX = g.getFontMetrics().charsWidth(END_MSG.toCharArray(), 0, END_MSG.length());
                fontX /= 2;
                g.drawString(END_MSG, (getWidth() / 2) - fontX, getHeight() / 2);
            }
            
            String output = myPos.x + ", " + myPos.y;
            g.setColor(Color.GREEN);
            int fontX = g.getFontMetrics().charsWidth(output.toCharArray(), 0, output.length());
            int fontY = g.getFontMetrics().getHeight();
            fontX /= 2;
            g.drawString(output, (getWidth() / 2) - fontX, getHeight() - fontY);
        }
    }
    
}
